package com.mall.web.controller.product;

import com.mall.common.annotation.Log;
import com.mall.common.core.controller.BaseController;
import com.mall.common.core.domain.AjaxResult;
import com.mall.common.core.page.TableDataInfo;
import com.mall.common.enums.BusinessType;
import com.mall.common.utils.poi.ExcelUtil;
import com.mall.product.domain.entity.ProSizeGroup;
import com.mall.product.service.ProSizeGroupService;
import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

/**
 * 尺码组Controller
 *
 * @author zhonglin
 * @date 2020-04-29
 */
@Controller
@RequestMapping("/product/sizeGroup")
public class ProSizeGroupController
    extends BaseController {

  private String prefix = "product/sizeGroup" ;

  @Autowired
  private ProSizeGroupService proSizeGroupService;

  @RequiresPermissions("product:sizeGroup:view")
  @GetMapping()
  public String sizeGroup() {

    return prefix + "/sizeGroup" ;
  }

  /**
   * 查询尺码组列表
   */
  @RequiresPermissions("product:sizeGroup:list")
  @PostMapping("/list")
  @ResponseBody
  public TableDataInfo list(ProSizeGroup proSizeGroup) {

    startPage();
    List<ProSizeGroup> list = proSizeGroupService.selectProSizeGroupList(proSizeGroup);
    return getDataTable(list);
  }

  /**
   * 导出尺码组列表
   */
  @RequiresPermissions("product:sizeGroup:export")
  @Log(title = "尺码组", businessType = BusinessType.EXPORT)
  @PostMapping("/export")
  @ResponseBody
  public AjaxResult export(ProSizeGroup proSizeGroup) {

    List<ProSizeGroup>      list = proSizeGroupService.selectProSizeGroupList(proSizeGroup);
    ExcelUtil<ProSizeGroup> util = new ExcelUtil<ProSizeGroup>(ProSizeGroup.class);
    return util.exportExcel(list, "sizeGroup");
  }

  /**
   * 新增尺码组
   */
  @GetMapping("/add")
  public String add() {

    return prefix + "/add" ;
  }

  /**
   * 新增保存尺码组
   */
  @RequiresPermissions("product:sizeGroup:add")
  @Log(title = "尺码组", businessType = BusinessType.INSERT)
  @PostMapping("/add")
  @ResponseBody
  public AjaxResult addSave(ProSizeGroup proSizeGroup) {

    return toAjax(proSizeGroupService.insertProSizeGroup(proSizeGroup));
  }

  /**
   * 修改尺码组
   */
  @GetMapping("/edit/{sizeGroupId}")
  public String edit(@PathVariable("sizeGroupId") Long sizeGroupId,
                     ModelMap mmap) {

    ProSizeGroup proSizeGroup = proSizeGroupService.selectProSizeGroupById(sizeGroupId);
    mmap.put("proSizeGroup", proSizeGroup);
    return prefix + "/edit" ;
  }

  /**
   * 修改保存尺码组
   */
  @RequiresPermissions("product:sizeGroup:edit")
  @Log(title = "尺码组", businessType = BusinessType.UPDATE)
  @PostMapping("/edit")
  @ResponseBody
  public AjaxResult editSave(ProSizeGroup proSizeGroup) {

    return toAjax(proSizeGroupService.updateProSizeGroup(proSizeGroup));
  }

  /**
   * 删除尺码组
   */
  @RequiresPermissions("product:sizeGroup:remove")
  @Log(title = "尺码组", businessType = BusinessType.DELETE)
  @PostMapping("/remove")
  @ResponseBody
  public AjaxResult remove(String ids) {

    return toAjax(proSizeGroupService.deleteProSizeGroupByIds(ids));
  }

}
